<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Workerman\Worker;

class Workerman extends Command
{
    /**
     * Workerman命令行.
     *
     * @var string
     */
//    protected $signature = 'Workerman {action} {--daemonize}';
    protected $signature = 'Workerman {action}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Workerman命令行';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        global $argv;
        $arg = $this->argument('action');
        $argv[1] = $arg;
//        $argv[2] = $this->argument('--daemonize') ? '-d' : '';

        global $work;

        $work = new Worker("websocket://0.0.0.0:2345");
        $work->uidConnections = array();//在线用户连接对象
        $work->uidInfo = array();//在线用户的用户信息

        $work->count = 4;

        $handler = \App::make('App\support\WorkermanHandler');
        $work->onConnect = array($handler,"connection");
        $work->onMessage = array($handler,"message");
        $work->onClose = array($handler,"close");
        $work->onWorkerStart = array($handler,"start");

        Worker::runAll();
    }
}
